home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
language
/
pcl_src.zoo
/
vector.lsp
< prev
next >
Wrap
Lisp/Scheme
|
1992-07-11
|
20KB
|
455 lines
;;;-*-Mode:LISP; Package:(PCL LISP 1000); Base:10; Syntax:Common-lisp -*-
;;;
;;; *************************************************************************
;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
;;; All rights reserved.
;;;
;;; Use and copying of this software and preparation of derivative works
;;; based upon this software are permitted. Any distribution of this
;;; software or derivative works must comply with all applicable United
;;; States export control laws.
;;;
;;; This software is made available AS IS, and Xerox Corporation makes no
;;; warranty about the software, its performance or its conformity to any
;;; specification.
;;;
;;; Any person obtaining a copy of this software is requested to send their
;;; name and post office or electronic mail address to:
;;; CommonLoops Coordinator
;;; Xerox PARC
;;; 3333 Coyote Hill Rd.
;;; Palo Alto, CA 94304
;;; (or send Arpanet mail to CommonLoops-Coordinator.pa@Xerox.arpa)
;;;
;;; Suggestions, comments and requests for improvements are also welcome.
;;; *************************************************************************
;;;
;;; Permutation vectors.
;;;
(in-package 'pcl)
(defmacro instance-slot-index-from-slots-layout (slots-layout slot-name)
`(locally (declare #.*optimize-speed*)
(let ((slots-left ,slots-layout))
(if slots-left
(block nil
(let ((index 0))
(declare (type index index))
(tagbody
begin-loop
(if (eq (car slots-left) ,slot-name)
(go return-index))
(setf index (the index (1+ index)))
(if (null (setf slots-left (cdr slots-left)))
(return NIL))
(go begin-loop)
return-index)
index))))))
(defmacro instance-slot-index (wrapper slot-name)
`(instance-slot-index-from-slots-layout
(wrapper-instance-slots-layout ,wrapper) ,slot-name))
;;;
;;;
;;;
(defun optimize-slot-value-by-class-p (class slot-name type)
(let ((slotd (find-slot-definition class slot-name)))
(and slotd
(or (not (eq *boot-state* 'complete))
(slot-accessor-std-p slotd type)))))
(defun optimize-generic-function-call (form required-parameters env)
(declare (ignore env required-parameters))
form
#||
(let* ((gf-name (car form))
(gf (gdefinition gf-name))
(arg-info (gf-arg-info gf))
(metatypes (arg-info-metatypes arg-info))
(nreq (length metatypes))
(applyp (arg-info-applyp arg-info)))
(declare (type index nreq))
(declare (ignore applyp))
(if (or (zerop nreq)
(not (<= nreq (length (cdr form))))
(not (every #'(lambda (arg mt)
(declare (ignore mt))
(when (consp arg)
(setq arg (un-the arg)))
(and (symbolp arg)
(memq arg required-parameters))
(let ((class-name (caddr (variable-declaration
'class arg env))))
(and class-name (not (eq 't class-name)))))
(cdr form) metatypes)))
form
form))||#) ;`(maybe-fast-gf-call ,(car form) ,(cdr form))
;; For calls to a gf:
; gf-call-info: (gf call-info-vector . gf-function-vector)
; call-info-vector: #(call-info1 ... call-infon)
; gf-function-vector: #(function1 ... functionn)
; --> once an entry is made in call-info-vector, it is never moved or removed
; call-info: (gf . arg-types)
; arg-type: a type. `(arg ,n) is not allowed here.
;; For calls from a method:
; method-gf-call-info: (method-specializers method-call-info-vector . ???)
; arg-type: a type or `(arg ,n)
; when arg-type is (arg n) the real type is either:
; the arg's specializer or
; (wrapper-eq ,wrapper) for a call appearing within a caching dfun gf
; every optimized gf in a method has an entry in the method's method-call-info-vector
; a macro: (get-call-cell mciv-index .all-wrappers.) ->
; index into the gf-function-vector
;(defmacro maybe-fast-gf-call (gf-name args)
; nil)
(defun can-optimize-access (form required-parameters env)
(let ((type (ecase (car form)
(slot-value 'reader)
(set-slot-value 'writer)
(slot-boundp 'boundp)))
(var (un-the (cadr form)))
(slot-name (eval (caddr form)))) ; known to be constant
(when (symbolp var)
(let* ((rebound? (caddr (variable-declaration 'variable-rebinding var env)))
(parameter-or-nil (car (memq (or rebound? var) required-parameters))))
(when parameter-or-nil
(let* ((class-name (caddr (variable-declaration
'class parameter-or-nil env)))
(class (find-class class-name nil)))
(when (if (and class
(class-on-class-precedence-list-p
*the-class-structure-object* class))
(optimize-slot-value-by-class-p class slot-name type)
(and class-name (not (eq class-name 't))))
(cons parameter-or-nil (or class class-name)))))))))
(defun optimize-slot-value (generic-function method slots sparameter form)
(if sparameter
(destructuring-bind (ignore ignore slot-name-form) form
(let ((slot-name (eval slot-name-form))
(class (if (consp sparameter) (cdr sparameter) *the-class-t*))
(parameter (if (consp sparameter) (car sparameter) sparameter)))
(if (eq *boot-state* 'complete)
(optimize-instance-access generic-function method class parameter
slots :read slot-name nil)
(optimize-std-instance-access class parameter
slots :read slot-name nil))))
`(fast-slot-value ,@(cdr form))))
(defun optimize-set-slot-value (generic-function method slots sparameter form)
(if sparameter
(destructuring-bind (ignore ignore slot-name-form new-value) form
(let ((slot-name (eval slot-name-form))
(class (if (consp sparameter) (cdr sparameter) *the-class-t*))
(parameter (if (consp sparameter) (car sparameter) sparameter)))
(if (eq *boot-state* 'complete)
(optimize-instance-access generic-function method class parameter
slots :write slot-name new-value)
(optimize-std-instance-access class parameter
slots :write slot-name new-value))))
`(fast-set-slot-value ,@(cdr form))))
(defun optimize-slot-boundp (generic-function method slots sparameter form)
(if sparameter
(destructuring-bind (ignore ignore slot-name-form new-value) form
(let ((slot-name (eval slot-name-form))
(class (if (consp sparameter) (cdr sparameter) *the-class-t*))
(parameter (if (consp sparameter) (car sparameter) sparameter)))
(if (eq *boot-state* 'complete)
(optimize-instance-access generic-function method class parameter
slots :boundp slot-name new-value)
(optimize-std-instance-access class parameter
slots :boundp slot-name new-value))))
`(fast-slot-boundp ,@(cdr form))))
;;;
;;; The <slots> argument is an alist, the CAR of each entry is the name of
;;; a required parameter to the function. The alist is in order, so the
;;; position of an entry in the alist corresponds to the argument's position
;;; in the lambda list.
;;;
(defun optimize-std-instance-access (class parameter slots read/write
slot-name new-value)
(let* ((parameter-entry (assq parameter slots))
(class-name (if (symbolp class) class (class-name class)))
(slot-entry (assq slot-name (cdr parameter-entry)))
(index-name
(or (second slot-entry)
(intern
(string-append "." (symbol-name parameter) "-"
(symbol-name slot-name) "-INDEX.")))))
(unless parameter-entry
(error "Internal error in slot optimization."))
(unless (or slot-entry
(skip-fast-slo